package book.cert;

import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

public class CertificateFactoryTest {

	public static void main(String[] args) throws CertificateException, IOException {
		
		CertificateFactory factory = CertificateFactory.getInstance("X.509");
		FileInputStream in = new FileInputStream("/Users/apple/Documents/demo.cer");
		Certificate cert = factory.generateCertificate(in);
		in.close();
		
		X509Certificate x509 = (X509Certificate)cert;
		PublicKey key = x509.getPublicKey();
		System.out.println(new BigInteger(key.getEncoded()));

		x509.checkValidity();
		System.out.println(x509.getVersion());
		System.out.println(x509.getBasicConstraints());
		System.out.println(x509.getSigAlgName());
		System.out.println(x509.getSigAlgOID());
		System.out.println(new BigInteger(x509.getSignature()));
	}
}
